<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药房管理-西药</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<style type="text/css">
.item {
	margin: 4px
}
</style>
</head>
<body>
	<script type="text/javascript">
		$(function() {
			//刷新
			$("#lfq-Pharmacydetail-reload").linkbutton({
				onClick : function() {
					$("#lfq-tb-Pharmacydetail-xiyao").datagrid({
						url : 'selectPharmacydetailVoXiYao',
						method : 'post'
					});
					$('#lfq-Pharmacydetail-search').searchbox("setValue", "");
				}
			});

			//搜索
			$('#lfq-Pharmacydetail-search').searchbox({
				searcher : function(value, name) {
					$("#lfq-tb-Pharmacydetail-xiyao").datagrid({
						url : 'selectPharmacydetailVoXiYaoLikeCpname',
						method : 'post',
						queryParams : {
							cpName : value
						}
					});
				}
			});

			//打开编辑窗口
			$("#lfq-Pharmacydetail-edit").linkbutton(
					{
						onClick : function() {
							var rows = $("#lfq-tb-Pharmacydetail-xiyao")
									.datagrid("getSelections");
							if (rows.length == 1) {
								$("#lfq-win-edit-Pharmacydetail")
										.window("open");
								var ygxqNo = rows[0].ygxqNo;

								$.getJSON("updatePharmacydetailByYgxqNo", {
									"ygxqNo" : ygxqNo
								}, function(data) {
									$("#lfq-form-edit-Pharmacydetail").form(
											"load", data);
								});

							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ rows.length + "条!");
							}
						}
					});

			//输入提示
			$("#lfq-ygxqSaleprice-aa").numberbox(
					{
						onChange : function(newValue, oldValue) {
							var kk = $("#lfq-ygxqPurchaseprice-bb").textbox(
									"getValue");
							if (parseInt(newValue) < parseInt(kk)) {
								$.messager.alert("提示", "您会亏本的!");
							} else if (parseInt(newValue) > parseInt(kk) * 2) {
								$.messager.alert("提示", "您的价格也太贵了吧!");
							}
						}
					});

			//修改
			$("#lfq-btn-PharmacydetailOk").linkbutton({
				onClick : function() {
					$('#lfq-form-edit-Pharmacydetail').form('submit', {
						url : 'submitPharmacydetailEditXiyao',
						onSubmit : function(param) {

						},
						success : function(data) {
							var json = eval("(" + data + ")");
							$.messager.alert("提示", json.reason);
							//重新加载表格
							$("#lfq-tb-Pharmacydetail-xiyao").datagrid({
								url : 'selectPharmacydetailVoXiYao',
								method : 'post'
							});
							$("#lfq-win-edit-Pharmacydetail").window("close");
						}
					});
				}
			});

			//取药
			$("#lfq-Pharmacydetail-quyao-xiyao").linkbutton({
				onClick : function() {
					$("#lfq-win-quyao-PharmacydetailXiyao").window("open");
					$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox("setValue","");
					var rows=$("#lfq-tb-quyao-xiyao-xq").datagrid("getRows");
					for(var i=rows.length-1;i>=0;i--){
						var index=$("#lfq-tb-quyao-xiyao-xq").datagrid("getRowIndex",rows[i]);
						$("#lfq-tb-quyao-xiyao-xq").datagrid("deleteRow",index);
					}
				}
			});

			//取药查询
			$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox({
				searcher : function(value, name) {
					if (value == null || value.length == 0) {

					} else {
						if (name == "处方取药") {
							$("#lfq-tb-quyao-xiyao-xq").datagrid({
								url : 'selectBingRenOperationDrugXiyao',
								method : 'post',
								queryParams : {
									dzcfNo : value
								}
							});
						} else if (name == "手术取药") {
							$("#lfq-tb-quyao-xiyao-xq").datagrid({
								url : 'selectShouShuOperationDrugXiyao',
								method : 'post',
								queryParams : {
									qyNo : value
								}
							});
						}
						$("#lfq-hidden-value").val(value);
						$("#lfq-hidden-name").val(name);
					}
				}
			});
			
			//查看详情
			$("#lfq-Pharmacydetail-xiyao-ckxq").linkbutton({onClick:function(){
				var val=$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox("getValue");
				var name=$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox("getName");
				if(val.length>0){
					if(name=="处方取药"){
						$("#lfq-tb-quyao-xiyao-xq2").datagrid({
							url : 'selectBingRenOperationDrugXq',
							method : 'post',
							queryParams : {
								dzcfNo : val
							}
						});
					}else if (name == "手术取药") {
						$("#lfq-tb-quyao-xiyao-xq2").datagrid({
							url : 'selectShouShuOperationDrugXq',
							method : 'post',
							queryParams : {
								qyNo : val
							}
						});
					}
				}else{
					$.messager.alert("提示", "请先输入查找编号!");
				}
			}});
			
			//订单详情事件
			var rows=$("#lfq-tb-quyao-xiyao-xq2").datagrid({onLoadSuccess:function(){
				var rows=$("#lfq-tb-quyao-xiyao-xq2").datagrid("getRows");
				if(rows.length>0){
					var val=$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox("getValue");
					var name=$('#lfq-Pharmacydetail-searchbox-xiyao').searchbox("getName");
					
					if(name=="处方取药"){
						$.getJSON("selectHisMedicalCardByDzcfNo", {
							"dzcfNo" : val
						}, function(data) {
							$("#br-name").html(data.brName);
							$("#br-sex").html(data.brSex);
							$("#br-age").html(data.brAge);
							$("#br-ylkNo").html(data.ylkNo);
							$("#lfq-win-quyao-PharmacydetailXiyao-xq").window("open");
						});
					}else if (name == "手术取药") {
						$.getJSON("selectHisMedicalCardByQyNo", {
							"qy" : val
						}, function(data) {
							$("#br-name").val(data.brName);
							$("#br-sex").val(data.brSex);
							$("#br-age").html(data.brAge);
							$("#br-ylkNo").val(data.ylkNo);
							$("#lfq-win-quyao-PharmacydetailXiyao-xq").window("open");
						});
					}
					
				}else{
					$.messager.alert("提示", "您输入的编号不存在!");
				}
			}});
			
			//取药完成
			$("#lfq-btn-quyao-PharmacydetailOk").linkbutton({onClick:function(){
				var value=$("#lfq-hidden-value").val();
				var name=$("#lfq-hidden-name").val();
				var rows=$("#lfq-tb-quyao-xiyao-xq").datagrid("getRows");
				var ygNo=$("#guanliren-yaofang").combogrid("getValue");
				if(ygNo.length>0){
					if(rows.length>0){
						if(name=="处方取药"){
							$.getJSON("quyaoChufangXiyao", {
								"dzcfNo" : value,
								"ygNo" : ygNo
							}, function(data) {
								$.messager.alert("提示", data.reason);
							});
						}else if(name=="手术取药"){
							$.getJSON("quyaoChufangZhongyao", {
								"qyNo" : value,
								"ygNo" : ygNo
							}, function(data) {
								$.messager.alert("提示", data.reason);
							});
						}
						
						$("#lfq-win-quyao-PharmacydetailXiyao").window("close");
						
					}else{
						$.messager.alert("提示", "没有可取的药品!");
					}
				}
				
			}});

		});
	</script>

	<table id="lfq-tb-Pharmacydetail-xiyao" class="easyui-datagrid"
		data-options="url:'selectPharmacydetailVoXiYao',
			fitColumns:true,
			fit:true,
			pagination: true,
			pageSize: 10,
			pageList: [10, 20, 30, 40],
			rownumbers: true,
			singleSelect:true,
			toolbar: '#lfq-tool-Pharmacydetail-xiyao',
			border:false
			">
		<thead>
			<tr>
				<th data-options="field:'ygxqNo',width:'5%', checkbox: true">ID</th>
				<th data-options="field:'cpName',width:'30%'">药品名称</th>
				<th data-options="field:'ygxqNumber',width:'15%'">数量</th>
				<th data-options="field:'ygxqPurchaseprice',width:'15%'">进价</th>
				<th data-options="field:'ygxqSaleprice',width:'15%'">售价</th>
				<th data-options="field:'yfxqUnit',width:'15%'">单位</th>
			</tr>
		</thead>
	</table>

	<div id="lfq-tool-Pharmacydetail-xiyao">
		<a id="lfq-Pharmacydetail-edit" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit',plain:true">修改信息</a> <a
			id="lfq-Pharmacydetail-quyao-xiyao" class="easyui-linkbutton"
			data-options="iconCls:'icon-xiyao',plain:true">取药</a> <a
			id="lfq-Pharmacydetail-reload" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <input
			id="lfq-Pharmacydetail-search" class="easyui-searchbox"
			data-options="menu: '#lfq-menu-xiyao', width: 260, prompt: '请输入药品名称'" />
	</div>

	<div id="lfq-menu-xiyao" style="width: 120px">
		<div data-options="name:'name'">药品名称</div>
	</div>

	<!-- 西药取药窗口 -->
	<div id="lfq-win-quyao-PharmacydetailXiyao" class="easyui-window"
		title="取药"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 700px; height: 440px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="lfq-form-quyao-Pharmacydetail-xi" method="post">
					<input id="lfq-Pharmacydetail-searchbox-xiyao"
						class="easyui-searchbox"
						data-options="menu: '#lfq-menu-quyao-xiyao', width: 260, prompt: '请输入查找ID'" />
					<a id="lfq-Pharmacydetail-xiyao-ckxq" class="easyui-linkbutton"
						data-options="plain:true">查看详情</a>
					<input id="lfq-hidden-value" type="hidden" value="0"/>
					<input id="lfq-hidden-name" type="hidden" value="0"/>
					
					&nbsp;&nbsp;&nbsp;&nbsp;管理人&nbsp;&nbsp;<select class="easyui-combogrid" id="guanliren-yaofang"
						data-options="
										width:'140', 
										panelWidth: '230',
										url:'yaofangAll',
										panelHeight:'auto',
										idField: 'ygNo',
										textField: 'ygName',
										columns:[[
										    {field:'ygNo',title:'编号',width:60},
							                {field:'ygName',title:'姓名',width:80},
							                {field:'ygPost',title:'职务',width:80}
							            ]]
										"></select>
					<div id="lfq-menu-quyao-xiyao" style="width: 120px">
						<div data-options="name:'处方取药'">处方取药</div>
						<div data-options="name:'手术取药'">手术取药</div>
					</div>
					<div style="margin: 5px;">
						<div id="zz1" class="easyui-tabs"
							style="width: 100%; margin-top: 10px;"
							data-options="plain:true,narrow:true">
							<div title="可取药品" style="padding: 10px;">
								<table id="lfq-tb-quyao-xiyao-xq" class="easyui-datagrid"
									style="height: 250px"
									data-options="
											pagination: true,
											pageSize: 5,
											pageList: [5, 10, 15, 20],
											singleSelect: true,
											rownumbers: true,
											method: 'get',
											width: '100%'
										">
									<thead>
										<tr>
											<th data-options="field:'cpName',width:'36%'">药物名称</th>
											<th data-options="field:'number',width:'18%'">数量</th>
											<th data-options="field:'count',width:'18%'">总价格</th>
											<th data-options="field:'unit',width:'18%'">单位</th>
										</tr>
									</thead>
								</table>
							</div>
						</div>
					</div>
				</form>
			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a id="lfq-btn-quyao-PharmacydetailOk" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok', plain:true">取药完成</a> <a
					class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel', plain:true"
					href="javascript:$('#lfq-win-quyao-PharmacydetailXiyao').window('close');"
					onclick="">取消</a>
			</div>
		</div>
	</div>

	<!-- 西药取药订单详情窗口 -->
	<div id="lfq-win-quyao-PharmacydetailXiyao-xq" class="easyui-window"
		title="该单详情"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 700px; height: 440px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
			    <div style="margin-bottom:8px;padding: 0px;">
			        <table width="90%">
			            <tr>
			                <td>病人姓名：<span style="color: red" id="br-name"></span></td>
			                <td>性别：<span style="color: red" id="br-sex"></span></td>
			                <td>年龄：<span style="color: red" id="br-age"></span></td>
			                <td>医疗卡号：<span style="color: red" id="br-ylkNo"></span></td>
			            </tr>
			        </table>
			    </div>
				<table id="lfq-tb-quyao-xiyao-xq2" class="easyui-datagrid"
					style="height: 313px"
					data-options="
							pagination: true,
							pageSize: 5,
							pageList: [5, 10, 15, 20],
							singleSelect: true,
							rownumbers: true,
							method: 'get',
							width: '100%'
						">
					<thead>
						<tr>
							<th data-options="field:'cpName',width:'32%'">药物名称</th>
							<th data-options="field:'number',width:'15%'">数量</th>
							<th data-options="field:'count',width:'15%'">总价格</th>
							<th data-options="field:'unit',width:'15%'">单位</th>
							<th data-options="field:'sta',width:'15%'">是否取药</th>
						</tr>
					</thead>
				</table>
				<div data-options="region:'south',border:false"
					style="text-align: right; padding: 5px 0 0;">
					<a class="easyui-linkbutton"
						data-options="iconCls:'icon-ok', plain:true"
						href="javascript:$('#lfq-win-quyao-PharmacydetailXiyao-xq').window('close');"
						onclick="">确定</a>
				</div>
			</div>
		</div>
	</div>

	<!-- 编辑信息窗口 -->
	<div id="lfq-win-edit-Pharmacydetail" class="easyui-window"
		title="编辑采购计划"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 400px; height: 300px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="lfq-form-edit-Pharmacydetail" method="post">
					<div class="item">
						<input name="ygxqNo" readonly="readonly" class="easyui-textbox"
							data-options="label: '详情编号', width: 200">
					</div>
					<div class="item">
						<input name="cpName" readonly="readonly" class="easyui-textbox"
							data-options="label: '药品名称', width: 250, required:true">
					</div>
					<div class="item">
						<input name="ygxqNumber" readonly="readonly"
							class="easyui-textbox"
							data-options="label: '数量', width: 250, required:true">
					</div>
					<div class="item">
						<input id="lfq-ygxqPurchaseprice-bb" name="ygxqPurchaseprice"
							readonly="readonly" class="easyui-textbox"
							data-options="label: '进价', width: 250, required:true">
					</div>
					<div class="item">
						<input id="lfq-ygxqSaleprice-aa" name="ygxqSaleprice"
							class="easyui-numberbox"
							data-options="label: '售价', width: 250, required:true,min:0,precision:2">
					</div>
					<div class="item">
						单位 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select
							name="yfxqUnit" class="easyui-combobox" style="width: 120px"
							data-options="panelHeight: 'auto'">
							<option value="箱">箱</option>
							<option value="盒">盒</option>
							<option value="斤">斤</option>
							<option value="包">包</option>
							<option value="件">件</option>
							<option value="个">个</option>
							<option value="卷">卷</option>
						</select>
					</div>
				</form>
			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a id="lfq-btn-PharmacydetailOk" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok', plain:true">确定</a> <a
					class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel', plain:true"
					href="javascript:$('#lfq-win-edit-Pharmacydetail').window('close');"
					onclick="">取消</a>
			</div>
		</div>
	</div>

</body>
</html>